#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int head[N];
int ver[N << 1], Next[N << 1], tot = 1;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int mx[N], mn[N];
int res;
void dfs(int u, int fu) {
  mx[u] = 0, mn[u] = 0;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (v == fu) continue;
    dfs(v, u);
    int now = mx[v] + 1;
    if (now > mn[u]) swap(mn[u], now);
    if (mn[u] > mx[u]) swap(mx[u], mn[u]);
  }
  res = max(res, mx[u] + mn[u]);
}
void solve() {
  cin >> n;
  rep(i, 2, n) {
    int u, v;
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  int ans = 0;
  rep(i, 1, n - 1) {
    int u = ver[i << 1], v = ver[i << 1 | 1];
    res = 0;
    dfs(u, v);
    int x = res;
    res = 0;
    dfs(v, u);
    int y = res;
    ans = max(ans, x * y);
  }
  cout << ans << endl;
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}